package org.nokatag.Connection;

import java.sql.Connection;

import javax.sql.DataSource;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.Concest;
import org.nokatag.system.ServletNokaContext;
import org.nokatag.system.SpringObjectFactory;

public class DataSourceForSpring extends SpringObjectFactory implements DBConnectionInterface{

	public Connection getConnection() {
		//ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletNokaContext.getServletContext());
		DataSource dataSource = (DataSource)bulidBean(Concest.DB_SPRING_SESSION_FACTORY);//ac.getBean(Concest.DB_SPRING_SESSION_FACTORY);
		try{
			ServletNokaContext.setDataSource(dataSource);
			return dataSource.getConnection();
		}catch(Exception se){
			BugInfoWrint.Print(se);
		}
		return null;
	}

	public void closeConnection(Connection con) {
		if(null!=con){
			try{con.close();}catch(Exception se){BugInfoWrint.Print(se);}
		}
	}

}

